﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ERPWinFormWork.Test
{
    public static class TestAPI
    {
        private static string _apiBaseUrl;
        public const string ApiBaseUrl = "http://localhost:5066/";
        //http://47.96.9.93:8000/testapi/

        private static bool _isInitialized;

        
        public static string TestApiBaseUrl
        {
            get
            {
                // 确保初始化完成（未完成时返回默认值避免卡顿）
                return _isInitialized ? _apiBaseUrl : TestApiBaseUrl;
            }
        }


        // 程序启动时调用此方法预加载配置
        public static async Task TestInitializeAsync()
        {
            if (_isInitialized) return;

            try
            {
                string key = "TestOnline";
                string configValue = await ApolloConfigManager.GetConfigAsync(key);
                _apiBaseUrl = configValue ?? ApiBaseUrl;
            }
            catch (Exception ex)
            {
                Console.WriteLine($"配置加载失败: {ex.Message}");
                _apiBaseUrl = ApiBaseUrl;
            }
            finally
            {
                _isInitialized = true; // 无论成功失败都标记为已初始化
            }
        }


    }
}
